aboutsummaryrefslogtreecommitdiffstats
path: root/src/routes/(app)/send/bitcoin/[address]/+layout.server.ts
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2024-11-26 13:08:08 -0800
committerAdam Soltys <[email protected]>2024-11-26 13:20:53 -0800
commit0bf630c39fe290ea2718eab7a0759d978c736ef9 (patch)
treea670c3ae954d5075c851126c2aca7a1a45d1b41d /src/routes/(app)/send/bitcoin/[address]/+layout.server.ts
parent41ee0027e1767e4d116330bdee2e0456fd45f940 (diff)
downloadcoinos-ui-0bf630c39fe290ea2718eab7a0759d978c736ef9.tar.gz
coinos-ui-0bf630c39fe290ea2718eab7a0759d978c736ef9.zip
bip21 and socket fixes
Diffstat (limited to 'src/routes/(app)/send/bitcoin/[address]/+layout.server.ts')
-rw-r--r--src/routes/(app)/send/bitcoin/[address]/+layout.server.ts18
1 files changed, 10 insertions, 8 deletions
diff --git a/src/routes/(app)/send/bitcoin/[address]/+layout.server.ts b/src/routes/(app)/send/bitcoin/[address]/+layout.server.ts
index 68191311..a321ec43 100644
--- a/src/routes/(app)/send/bitcoin/[address]/+layout.server.ts
+++ b/src/routes/(app)/send/bitcoin/[address]/+layout.server.ts
@@ -4,20 +4,22 @@ import { redirect } from "@sveltejs/kit";
export async function load({ cookies, params, parent }) {
const { user } = await parent();
const aid = cookies.get("aid");
- const { address } = params;
+ const { address, amount } = params;
const { balance } = await get(`/account/${aid}`, auth(cookies));
+ let invoice;
try {
- const invoice = await get(`/invoice/${address}`);
-
- if (invoice) {
- const recipient = await get(`/users/${invoice.uid}`);
- if (recipient?.id !== user.id)
- redirect(307, `/pay/${recipient.username}`);
- }
+ invoice = await get(`/invoice/${address}`);
} catch (e) {
// invoice not found
}
+ if (invoice) {
+ const recipient = await get(`/users/${invoice.uid}`);
+ let r = `/pay/${recipient.username}`;
+ if (amount) r += `/${amount}`;
+ if (recipient?.id !== user.id) redirect(307, r);
+ }
+
return { balance };
}